<template>
  <div id="consumablesReceive" v-loading="loading">
    <v-tableTitle
      :btnConfig="btnConfig"
      :tableSelectData="tableSelectData"
      :title="$t('manage.consumablereceivesetting')"
      @newCreate="newCreate"
      @del="del"
    ></v-tableTitle>
    <v-table
      :page="page"
      :pageSize="pageSize"
      :tableConfig="tableConfig"
      :tableData="tableData"
      :total="total"
      @findData="getTableData"
      @getTableData="getTableData"
      @searhData="searhData"
      @selectData="selectData"
      @setdialog="setdialog"
      @upData="getTableData"
      ref="table"
    ></v-table>
  </div>
</template>

<script type="text/ecmascript-6">
import tableTitle from "commons/TableTitle";
import table from "commons/Table";
import baseMixin from "@/mixins/BaseMixin";
import config from "./Config";
import bus from "../../../../bus/bus"

export default {
    name: "consumablesReceive",
    mixins: [baseMixin, config],
    data() {
        return {
            loading: false,
            tableConfig: [
                {
                    label: this.$t('manage.rtx_consumablereceivekey'),
                    prop: "rtx_consumablereceivekey",
                    input: "input",
                },
                {
                    label: this.$t('manage.rtx_consumablekey'),
                    prop: "rtx_consumablekey",
                    input: "input"
                },
                {
                    label: this.$t('manage.receive_person'),
                    prop: "receive_person",
                    input: "input",
                },
                {
                    label: this.$t('common.type'),
                    prop: "rtx_type",
                    input: "select",
                    options: [
                        {code: '1', description: this.$t('code.rtx_type3')},
                        {code: '2', description: this.$t('code.rtx_type4')}
                    ]
                },
                {
                    label: this.$t('manage.balanceqty'),
                    prop: "balanceqty",
                    input: "input",
                },
                {
                    label: this.$t('manage.receivedate'),
                    prop: "receivedate",
                    input: "date",
                }
            ],
            tableData: [],
          page: 1,
            pageSize: 10,
            total: 10,
            tableSelectData: [],
            tableSearhData: {},
        };
    },
    computed: {
        btnConfig() {
            return [
                {label: this.$t('common.create'), certigier: this.newStatus, invalid: "newCreate"},
                {label: this.$t('common.delete'), certigier: this.deleteStatus, disabled: true, invalid: "del"},
            ]
        }
    },
    created() {
    },
    methods: {
        newCreate() {
        },
        del(data) {
        },
        //选中的内容
        selectData(data) {
            this.tableSelectData = data;
        },
        async getTableData(page, data) {
            try {
                this.loading = true;
                let res = await this.$api.post(`/queryConsumablesReceiveList/${page}`, data);
                
                    this.tableData = res.page.list;
                  this.page = res.page.curpage;
                    this.pageSize = res.page.pageSize;
                    this.total = res.page.total;
                
            } catch (e) {
                this.$message.error(e);
            } finally {
                this.loading = false;
            }
        },
        //搜索的值
        searhData(data, up) {
            if (!up) {
                this.tableSearhData = data;
            } else {
                this.tableSearhData = data;
                this.getTableData(1, this.tableSearhData);
            }
        },
        //设置弹框
        setdialog(data) {
            this.$store.commit("setRouteData", data);
            this.$router.push({name: 'consumablesReceiveDeawer'});
        },
    },
    mounted() {
        
        this.$store.commit("setSkip", {});
        this.$store.commit("setNewFlag", false);
        this.$store.commit("setRouteData", {});
        this.getTableData(1, {});
    },
    watch: {
        tableSelectData(data) {
            if (this.permissionStatus) {
                if (data.length > 0) {
                    this.deleteStatus = false;
                } else {
                    this.deleteStatus = true;
                }
            }
        }
    },
    components: {
        "v-tableTitle": tableTitle,
        "v-table": table,
    }
};
</script>

<style scoped>
#consumablesReceive {
  width: 100%;
  height: 99%;
  padding-top: 6px;
}
</style>
